from src.classification.predict import Classification
from src.predict import Identification
from src.predict import ClassifyAndIdentify


import argparse

classfy_model = Classification()
identify_model = Identification()
classfy_identify_mdoel = ClassifyAndIdentify()


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--type',  metavar='-t', type=str, help='classify/identificaty/classify_identify')

    # classify
    parser.add_argument('--price_type', metavar='-pt', type=str, help='设备资源库/材料资源库')
    parser.add_argument('--topk', metavar='-tk', type=int, help='return topk result')

    # classify_identify
    parser.add_argument('--classification', metavar='-c', type=str, help='material classification', default='')
    parser.add_argument('--price_conditions', metavar='-pc', type=str, help='price_conditions')
    parser.add_argument('--material_name', metavar='-mn', type=str, help='materialName')
    parser.add_argument('--sepc', metavar='-se', type=str, help='sepc')

    # classify_identify
    args = parser.parse_args()

    if args.type == 'classify':
        price_type = args.price_type
        materialName = args.material_name
        sepc = args.sepc
        topk = args.topk
        data = [{"material_name": materialName, "material_sepc": sepc}]
        result = classfy_model.predict(price_type, data, topk)
        for i, item in enumerate(result[0]):
            print(i, item)

    elif args.type == 'identificaty':
        price_type = args.price_type
        classification = args.classification
        materialName = args.material_name
        sepc = args.sepc
        price_conditions = eval(args.price_conditions)
        topk = int(args.topk)
        result = identify_model.predict(price_type, classification, materialName, sepc, price_conditions, topk)
        for i, item in enumerate(result):
            print(i, ':', item)

    elif args.type == 'classify_identify':
        price_type = args.price_type
        material_name = args.material_name
        material_sepc = args.sepc
        price_conditions = eval(args.price_conditions)
        topk = int(args.topk)
        result = classfy_identify_mdoel.predict(price_type,  material_name, material_sepc, price_conditions, topk)
        for i, item in enumerate(result):
            print(i, ':', item)

    else:
        print("usage: python inference.py --type [classify/identificaty/classify_identify] ")


'''
python inference.py --type="classify" --price_type=材料资源库   --material_name="钢绞线"  --sepc="" --topk=10

python inference.py --type=identificaty --price_type=材料资源库  --price_conditions="{'price_condition_one': {'fir_area': '', 'seco_area': '总部', 'third_area': '', 'particular_year': '2019','time_version': ''},'price_condition_two': {'fir_area': '', 'seco_area': '', 'third_area': '', 'particular_year': '','time_version': ''},'price_condition_three': {'fir_area': '', 'seco_area': '', 'third_area': '', 'particular_year': '', 'time_version': ''},}"    --material_name="钢绞线"  --sepc="" --topk=10

python inference.py --type=classify_identify --price_type=材料资源库  --price_conditions="{'price_condition_one': {'fir_area': '', 'seco_area': '总部', 'third_area': '', 'particular_year': '2019','time_version': ''},'price_condition_two': {'fir_area': '', 'seco_area': '', 'third_area': '', 'particular_year': '','time_version': ''},'price_condition_three': {'fir_area': '', 'seco_area': '', 'third_area': '', 'particular_year': '', 'time_version': ''},}"    --material_name="钢绞线"  --sepc="" --topk=10
'''
